import React from "react";
import * as am4core from "@amcharts/amcharts4/core";
import * as am4charts from "@amcharts/amcharts4/charts";

class AmchartCom {
  constructor(props) {
    let { id, chartData, xLine } = props;
    this.chartInstance = undefined;
    this.xAxis = undefined;
    this.yAxis = undefined;
    this.id = id;
    this.chartData = chartData;
    this.xLine = xLine;
  }
  createColumn = ({ xData, yData, name = "" }) => {
    const columnSeries = this.chartInstance.series.push(
      new am4charts.ColumnSeries()
    );
    columnSeries.dataFields.valueX = xData;
    columnSeries.dataFields.valueY = yData;
  };
  //   渲染图表实例
  renderChart() {
    const { data } = this.props;
    if (!this.chartInstance) {
      this.chartInstance = am4core.create(this.id, am4charts.XYChart);
    }
    if (!this.xAxis) {
      this.xAxis = this.chartInstance.xAxes.push(new am4charts.ValueAxis());
    }
    if (!this.yAxis) {
      this.yAxis = this.chartInstance.yAxes.push(new am4charts.ValueAxis());
    }
  }
}
export default AmchartCom;
